package com.itheima.UDPdemo.UDP三种通信方式.组播;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.Scanner;

public class SendMessageDemo {
    public static void main(String[] args) throws IOException {
    /*
    * 组播
    * */
        MulticastSocket ms=new MulticastSocket();//单播对象换成组播对象
        //DatagramSocket ds=new DatagramSocket();

        String test= "fanqinyu";
        byte[] bytes=test.getBytes();
        //InetAddress inetAddress=InetAddress.getByName("127.0.0.1");
        InetAddress inetAddress=InetAddress.getByName("224.0.0.1");//ip地址换成组播地址
        int port=10086;
        DatagramPacket dp=new DatagramPacket(bytes,bytes.length,inetAddress,port);

        ms.send(dp);

        ms.close();
    }
}
